package gui.util;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class PeriodRenderer extends DefaultTableCellRenderer {

	private int periodLimit = 1;
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		if( value instanceof Integer ) {
			int period = (Integer) value;
            if( period >= periodLimit ) {
            	cell.setForeground(Color.red);
            } else {
            	cell.setForeground(Color.blue);
            }
		}
		return cell;
	}
	
	public void setPeriodLimit(int period) {
		if (period > 0) {
			periodLimit = period;
		}
	}
	
}
